<?php
require_once "config.php";
require_once "weixin_info.php";
$sql = $mysql->query("select * from dyspw_member where  id = {$_SESSION['Member_info'][0]['id']} ");
$member_info = $sql->fetch_all(MYSQLI_ASSOC);
$invite_code = empty($_GET['invite_code']) ? '' : $_GET['invite_code'];
if(!empty($invite_code)){
    // print_r($member_info);exit;
    if($member_info[0]['is_vip'] == 3){
        header("Location: https://5p8.fyh5p8.com/xiaochengxu/member.php");
    }
    if($member_info[0]['is_vip'] == 4){
        header("Location: https://5p8.fyh5p8.com/xiaochengxu/personalCenter.php");
    }

}
// print_r($member_info);exit;
// echo $member_info[0]['shop_spot'];exit;
$fenlei = $mysql->query("select * from dyspw_weblinktype where parentid = 0 and checkinfo = true");
$fenlei_rows = $fenlei->fetch_all(MYSQLI_ASSOC);
 ?>

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title><?php if($member_info[0]['is_vip'] == 3 || !empty($invite_code)){echo "商户";}else{ echo "个人";} ?>设置</title>
    <script src="js/mui.min.js"></script>
    <link href="css/mui.min.css" rel="stylesheet" />
    <script src="js/jquery-2.2.4.min.js" type="text/javascript"></script>
    <link href="css/shopSetting.css" rel="stylesheet" />
        <script src="js/layer/layer.js" type="text/javascript"></script>
    <script type="text/javascript" charset="utf-8">
        mui.init();
    </script>
    <style media="screen">
    .container .main .card .mui-table-view-cell input{text-align: right;font-size: 14px;margin-bottom: 0px;}
    input::-webkit-input-placeholder{
        color:#ccc;
        font-size: 12px;
    }
    </style>
<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?cb5d49b07e0a753dc8ee27ba2c73495d";
  var s = document.getElementsByTagName("script")[0];
  s.parentNode.insertBefore(hm, s);
})();
</script>
</head>

<body>
    <div class="container">
        <div class="navbar">
            <div class="backBtn">
                <a href="javascript:history.back(-1);"><span class="mui-icon mui-icon-arrowleft"></span></a>
            </div>
            <span><?php if($member_info[0]['is_vip'] == 3 || !empty($invite_code)){echo "商户";}else{ echo "个人";} ?>设置</span>
        </div>
        <div class="main">
            <div class="card">
                <ul class="mui-table-view mui-input-row">
                    <li class="mui-table-view-cell ">
                        <label class="lab">头像<em style="color:red;">*</em> </label>
                        <div class="file_up avatar" shop_type="avatar">
                            <input type="hidden" name="avatar" value="<?php echo  $member_info[0]['avatar']; ?>">
                            <img class="mui-media-object mui-pull-right mui-ellipsis img "  src="<?php echo  $member_info[0]['avatar']; ?>">
                        </div>
                    </li>
                    <li class="mui-table-view-cell name">
                        <label class="lab">名称<em style="color:red;">*</em> </label>
                        <div class="mui-pull-right mui-ellipsis info">
                            <input type="text" name="username" align="right" placeholder="商铺名称" maxlength="10" value="<?php echo $member_info[0]['username']; ?>" style="border:0px;">
                        </div>
                    </li>
                    <li class="mui-table-view-cell">
                        <label class="lab">简介</label>
                        <div class="mui-pull-right mui-ellipsis info ">
                            <input type="text" name="intro"  placeholder="商铺简介" maxlength="50" value="<?php echo $member_info[0]['intro'] ?>" style="border:0px;">
                        </div>

                    </li>
                    <li class="mui-table-view-cell">
                        <label class="lab">手机号码<em style="color:red;">*</em></label>
                        <div class="mui-pull-right mui-ellipsis info">
                            <input type="number" name="mobile" placeholder="手机号码" value="<?php echo $member_info[0]['mobile'] ?>" style="border:0px;">
                        </div>
                    </li>
                    <li class="mui-table-view-cell">
                        <label class="lab">分类<em style="color:red;">*</em></label>
                        <div class="mui-pull-right mui-ellipsis info">
                            <select class="sort" name="sort" style="margin-bottom: 0px;direction: rtl;font-size: 14px;">
                                <option value="">选择分类</option>
                                <?php foreach ($fenlei_rows as $key => $val): ?>
                                    <option value="<?php echo $val['id'] ?>" <?php if($member_info[0]['sort'] == $val['id']){echo "selected";} ?>><?php echo $val['classname'] ?></option>
                                <?php endforeach; ?>
                            </select>
                            <input type="number" name="mobile" placeholder="手机号码" value="<?php echo $member_info[0]['mobile'] ?>" style="border:0px;">
                        </div>
                    </li>
                    <li class="mui-table-view-cell ">
                        <label class="lab" style="margin-top: 15px;">微信二维码</label>

                        <div class="logo mui-pull-right mui-ellipsis file_up wx_img" shop_type="wx_img">
                            <?php if(!empty($member_info[0]['wx_img'])){ ?>
                                <img src="<?php echo  $member_info[0]['wx_img']  ?>" alt="" style="width: 50px;">
                                <!-- <input class="addBorder" accept="image/*" type="file" > -->
                            <?php }else{?>
                                <div class="round">+</div>
                                <img  src="" alt="">
                            <?php } ?>
                            <input type="hidden" name="wx_img" value="<?php echo  $member_info[0]['wx_img']  ?>">

                        </div>
                    </li>
                    <?php if($member_info[0]['is_vip'] == 3 || !empty($invite_code)){ ?>
                    <li class="mui-table-view-cell">
                        <label class="lab">商铺地址<em style="color:red;">*</em> </label>
                        <div class="mui-pull-right mui-ellipsis info">
                            <!-- <input type="hidden" name="shop_add" value=""> -->
                            <!-- <a href="shop_add.php"><?php if(!empty($member_info[0]['shop_add'])){echo $member_info[0]['shop_add'];}else{echo "<button type='button' name='button'>获取地址</button>";}  ?></a> -->
                            <input type="text"id="shop_add" name="shop_add" placeholder="商铺地址" value="<?php echo $member_info[0]['shop_add']; ?>" style="border:0px;"/>
                            <input type="hidden" name="shop_lng" value="<?php echo $member_info[0]['shop_lng']; ?>">
                            <input type="hidden" name="shop_lat" value="<?php echo $member_info[0]['shop_lat']; ?>">
                        </div>
                    </li>
                    <li><div id="wrapper" style="width: 100%;height: 200px;"></div></li>
                    <?php } ?>
                </ul>
            </div>
            <?php if($member_info[0]['is_vip'] == 3 || !empty($invite_code)){ ?>
            <div class="card">
                <ul class="mui-table-view mui-input-row">
                    <li class="mui-table-view-cell ">
                        <label class="lab">拍客返点</label>
                        <span class="radio_inline mui-radio mui-pull-right mui-ellipsis">
                            <input name="shop_spot" id="radio_is" type="radio"  value="1" <?php if($member_info[0]['shop_spot'] !== ''){echo "checked";} ?>>
                            <label for="radio_is">有</label>
                            <input name="shop_spot" id="radio_no" type="radio" value="0" <?php if(empty($member_info[0]['shop_spot'])){echo "checked";} ?>>
                            <label for="radio_no">无</label>
                        </span>
                    </li>
                    <li class="mui-table-view-cell ">
                        <label class="lab">拍客推荐顾客购买成功返点</label>

                        <div class="mui-pull-right mui-ellipsis info">
                            <input type="number" name="shop_spot_ratio" placeholder="返点比例" value="<?php echo $member_info[0]['shop_spot_ratio'] ?>" style="border:0px;width: 90%;">%
                        </div>
                    </li>
                    <li class="mui-table-view-cell zanBox">
                        <label class="lab">拍客视频获赞
                            <em style="width: 30px;display: inline-block;border-bottom: 1px solid #ddd;position: relative;top: 5px;"> <?php echo $member_info[0]['praise_num']; ?></em>
                            个得</label>
                        <div class="mui-pull-right mui-ellipsis info praise_award"><?php if(!empty( $member_info[0]['praise_award'])){echo $member_info[0]['praise_award'];}else{echo "XXX商品";} ?></div>
                    </li>
                </ul>
            </div>
            <div class="card">
                <ul class="mui-table-view mui-input-row">
                    <li class="mui-table-view-cell">
                        <label class="lab">邮箱<em style="color:red;">*</em></label>
                        <div class="mui-pull-right mui-ellipsis info">
                            <input type="text" name="qq_email" placeholder="邮箱" value="<?php echo $member_info[0]['qq_email'] ?>" style="border:0px;">
                        </div>
                    </li>
                    <li class="mui-table-view-cell" >
                        <label class="lab" style="width:100%;">营业执照 <em style="display: inline-block;color: #8d97b2;font-style:normal;float: right;width: 75%;text-align: right;">
                            <img src="images/shop_wenjian.png" alt="" style="    width: 15px;    margin-right: 5px;position: relative;top: 3px;">营业执照，银行卡，身份证三者须统一</em>
                         </label>
                    </li>
                    <li class="mui-table-view-cell " >
                        <div class="logo2 shop_yyzz file_up" shop_type="shop_yyzz" style="height:auto;width: 100%;">
                            <?php if(!empty($member_info[0]['shop_yyzz'])){ ?>
                                <img src="<?php echo  $member_info[0]['shop_yyzz']  ?>" alt="">
                            <?php }else{?>
                                <div class="round2" style="margin: 40px 0px;">+</div>
                                <img  src="" alt="">
                            <?php } ?>
                            <input type="hidden" name="shop_yyzz" value="<?php echo  $member_info[0]['shop_yyzz']  ?>">
                        </div>
                    </li>
                    <li style="    display: block;width: 100%;height: 10px;background: #f6f5f5;"></li>
                    <li class="mui-table-view-cell" >
                        <label class="lab" style="width:100%;">卫生许可证 <em style="display: inline-block;color: #8d97b2;font-style:normal;float: right;width: 75%;text-align: right;">
                            <img src="images/shop_wenjian.png" alt="" style="    width: 15px;    margin-right: 5px;position: relative;top: 3px;">营业执照，银行卡，身份证三者须统一</em>
                         </label>
                    </li>
                    <li class="mui-table-view-cell " >
                        <div class="logo2 shop_hygiene file_up" shop_type="shop_hygiene" style="height:auto;width: 100%;">
                            <?php if(!empty($member_info[0]['shop_hygiene'])){ ?>
                                <img src="<?php echo  $member_info[0]['shop_hygiene']  ?>" alt="">
                            <?php }else{?>
                                <div class="round2" style="margin: 40px 0px;">+</div>
                                <img  src="" alt="">
                            <?php } ?>
                            <input type="hidden" name="shop_hygiene" value="<?php echo  $member_info[0]['shop_hygiene']  ?>">
                        </div>
                    </li>
                    <li style="    display: block;width: 100%;height: 10px;background: #f6f5f5;"></li>
                    <li class="mui-table-view-cell" >
                        <label class="lab" style="width:100%;">店铺门头 </label>
                    </li>
                    <li class="mui-table-view-cell " >
                        <div class="logo2 shop_doorway file_up" shop_type="shop_doorway" style="height:auto;width: 100%;">
                            <?php if(!empty($member_info[0]['shop_doorway'])){ ?>
                                <img src="<?php echo  $member_info[0]['shop_doorway']  ?>" alt="">
                            <?php }else{?>
                                <div class="round2" style="margin: 40px 0px;">+</div>
                                <img  src="" alt="">
                            <?php } ?>
                            <input type="hidden" name="shop_doorway" value="<?php echo  $member_info[0]['shop_doorway']  ?>">
                        </div>
                    </li>
                    <li style="    display: block;width: 100%;height: 10px;background: #f6f5f5;"></li>
                    <li class="mui-table-view-cell" >
                        <label class="lab" style="width:100%;">店内照片 </label>
                    </li>
                    <li class="mui-table-view-cell " >
                        <div class="logo2 shop_images file_up" shop_type="shop_images" style="height:auto;width: 100%;">
                            <?php if(!empty($member_info[0]['shop_images'])){ ?>
                                <img src="<?php echo  $member_info[0]['shop_images']  ?>" alt="">
                            <?php }else{?>
                                <div class="round2" style="margin: 40px 0px;">+</div>
                                <img  src="" alt="">
                            <?php } ?>
                            <input type="hidden" name="shop_images" value="<?php echo  $member_info[0]['shop_images']  ?>">
                        </div>
                    </li>
                    <li style="    display: block;width: 100%;height: 10px;background: #f6f5f5;"></li>
                    <li class="mui-table-view-cell" >
                        <label class="lab" style="width:100%;">结算银行卡 <em style="display: inline-block;color: #8d97b2;font-style:normal;float: right;width: 75%;text-align: right;">
                            <img src="images/shop_wenjian.png" alt="" style="    width: 15px;    margin-right: 5px;position: relative;top: 3px;">营业执照，银行卡，身份证三者须统一</em>
                         </label>
                    </li>
                    <li class="mui-table-view-cell " >
                        <div class="logo2 shop_bank file_up" shop_type="shop_bank" style="height:auto;width: 100%;">
                            <?php if(!empty($member_info[0]['shop_bank'])){ ?>
                                <img src="<?php echo  $member_info[0]['shop_bank']  ?>" alt="">
                            <?php }else{?>
                                <div class="round2" style="margin: 40px 0px;">+</div>
                                <img  src="" alt="">
                            <?php } ?>
                            <input type="hidden" name="shop_bank" value="<?php echo  $member_info[0]['shop_bank']  ?>">
                        </div>
                    </li>
                    <li class="mui-table-view-cell">
                        <label class="lab">开户行地址<em style="color:red;">*</em></label>
                        <div class="mui-pull-right mui-ellipsis info">
                            <input type="text" name="shop_bank_add" placeholder="开户行地址" value="<?php echo $member_info[0]['shop_bank_add'] ?>" style="border:0px;">
                        </div>
                    </li>
                    <li style="    display: block;width: 100%;height: 10px;background: #f6f5f5;"></li>
                    <li class="mui-table-view-cell" >
                        <label class="lab" style="width:100%;">身份证 <em style="display: inline-block;color: #8d97b2;font-style:normal;float: right;width: 75%;text-align: right;">
                            <img src="images/shop_wenjian.png" alt="" style="    width: 15px;    margin-right: 5px;position: relative;top: 3px;">营业执照，银行卡，身份证三者须统一</em>
                         </label>
                    </li>
                    <li class="mui-table-view-cell " >
                        <div class="logo2 shop_just file_up" shop_type="shop_just" style="height:auto;width: 100%;margin-right: 5px;">
                            <?php if(!empty($member_info[0]['shop_just'])){ ?>
                                <img src="<?php echo  $member_info[0]['shop_just']  ?>" alt="" style="width:50%;">
                            <?php }else{?>
                                <div class="round2" style="margin: 40px 0px;">+</div>
                                <img  src="" alt="" style="width:50%; display:none;">
                            <?php } ?>
                            <input type="hidden" name="shop_just" value="<?php echo  $member_info[0]['shop_just']  ?>">

                        </div>
                        <div class="logo2 shop_back file_up" shop_type="shop_back" style="height:auto;width: 100%;">
                            <?php if(!empty($member_info[0]['shop_back'])){ ?>
                                <img src="<?php echo  $member_info[0]['shop_back']  ?>" alt="" style="width:50%;">
                            <?php }else{?>
                                <div class="round2" style="margin: 40px 0px;">+</div>
                                <img  src="" alt="" style="width:50%; display:none;">
                            <?php } ?>
                            <input type="hidden" name="shop_back" value="<?php echo  $member_info[0]['shop_back']  ?>">
                        </div>
                    </li>
                    <li class="mui-table-view-cell " style="text-align:center;padding-top:0px;"><p style="width:50%;">正面</p><p style="width:50%;">反面</p></li>
                </ul>
            </div>
            <?php } ?>
            <div class="btnBox">
                <button type="button" class="mui-btn mui-btn-primary">保存信息</button>
            </div>
        </div>
        <div class="dialog">
            <div class="dialogMain">
                <div class="dialogTitle">
                    <span class="titleName"></span>
                    <span class="mui-icon mui-icon-closeempty"></span>
                </div>
                <div class="dialogContent">
                    <div class="nameDialog">
                        <div class="mui-input-row">
                            <input type="text" class="nameInput" placeholder="请输入用户名">
                        </div>
                    </div>

                    <!-- <div class="zanDialog">
                        <div class="zanDialogContent">
                            <div class="textareaInput">
                                <textarea class="textarea" id="" placeholder="输入拍客视频获赞详情" cols="30" rows="3"></textarea>
                            </div>
                            <div class="imgBox">
                                <div class="imgSelector">
                                    <div class="placeholder file_up praise_img" shop_type="praise_img">

                                    </div>
                                </div>
                                <div class="mark">图片和文字可以二选一</div>
                            </div>
                        </div>
                    </div> -->

                    <div class="zanRewardDiaLog">
                        <div class="zanDialogContent">
                            <div class="textareaInput">
                                <textarea class="textarea" name="praise_award" id="" placeholder="输入获赞奖励" cols="30" rows="3"><?php echo $member_info[0]['praise_award'] ?></textarea>
                            </div>
                            <div class="imgBox">
                                <div class="imgSelector">
                                    <div class="placeholder file_up praise_img" shop_type="praise_img" style="padding-top:0px;">
                                        <?php if(!empty($member_info[0]['praise_img'])){ ?>
                                            <img src="<?php echo  $member_info[0]['praise_img']  ?>" alt="">
                                        <?php }else{?>
                                            <div style="    position: relative;top: 50%;transform: translateY(-50%);font-size: 30px;">+</div>
                                            <img  src="" alt="">
                                        <?php } ?>
                                        <input type="hidden" name="praise_img" value="<?php echo  $member_info[0]['praise_img']  ?>">
                                    </div>
                                </div>
                                <div class="mark">图片和文字可以二选一</div>
                            </div>
                        </div>
                    </div>

                    <div class="zanNumDialog">
                        <div class="mui-input-row">
                            <input type="number" name="praise_num" class="nameInput" placeholder="输入获赞数量" value="<?php echo  $member_info[0]['praise_num']  ?>">
                        </div>
                    </div>
                    <div class="rewardPercentageDialog">
                        <div class="mui-input-row">
                            <input type="number" class="nameInput" placeholder="输入返点百分比">
                        </div>
                    </div>
                    <input type="hidden" name="invite_code" value="<?php echo $invite_code; ?>">
                    <button class="confirmBtn">确认</button>
                </div>
            </div>
        </div>

        <!-- <div id="sheet1" class="mui-popover mui-popover-bottom mui-popover-action ">
            <div class="popoverBox">
                <ul class="mui-table-view menu">
                    <li class="mui-table-view-cell">
                        <a href="#">从手机相册选择</a>
                    </li>
                </ul>
                <ul class="mui-table-view cancel">
                    <li class="mui-table-view-cell">
                        <a href="#sheet1">取消</a>
                    </li>
                </ul>
            </div>
        </div> -->
        <!-- <div id="sheet2" class="mui-popover mui-popover-bottom mui-popover-action ">
            <div class="popoverBox">
                <ul class="mui-table-view menu">
                    <li class="mui-table-view-cell">
                        <a href="#">从手机相册选择</a>
                    </li>
                    <li class="mui-table-view-cell">
                        <a href="#">拍照</a>
                    </li>
                </ul>
                <ul class="mui-table-view cancel">
                    <li class="mui-table-view-cell">
                        <a href="#sheet1">取消</a>
                    </li>
                </ul>
            </div>
        </div> -->
        <input type="file" id="file" class="filepath" onchange="changepic(this)"
            accept="image/*" shop_type="" hidden/>
        <!-- <input type="file" accept="image/*" > -->
        <canvas id="canvas" style="display: none;"></canvas>
    </div>
    <script src="./js/jquery-2.2.4.min.js"></script>
    <script src="./js/compress.js"></script>
    <script src="https://a.amap.com/jsapi_demos/static/demo-center/js/demoutils.js"></script>
    <script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=d021bae86db1d54dddc4071a5123749c&plugin=AMap.Geocoder"></script>
    <script>
            function isPhoneNo(phone) {
                var pattern = /^1[34578]\d{9}$/;
                return pattern.test(phone);
            }
        //提交保存
        $(".mui-btn").click(function(){
            var data = {};
            data['avatar'] = $("input[name='avatar']").val();
            data['username'] = $("input[name='username']").val();
            data['intro'] = $("input[name='intro']").val();
            data['wx_img'] = $("input[name='wx_img']").val();
            data['shop_add'] = $("input[name='shop_add']").val();
            data['shop_lng'] = $("input[name='shop_lng']").val();
            data['mobile'] = $("input[name='mobile']").val();
            data['sort'] = $("select[name='sort']").val();
            data['shop_lat'] = $("input[name='shop_lat']").val();
            data['shop_spot'] = $("input[name='shop_spot']:checked").val();
            data['shop_spot_ratio'] = $("input[name='shop_spot_ratio']").val();
            data['praise_num'] = $("input[name='praise_num']").val();//
            data['praise_img'] = $("input[name='praise_img']").val();
            data['praise_award'] = $("textarea[name='praise_award']").val();
            data['shop_yyzz'] = $("input[name='shop_yyzz']").val();
            data['shop_hygiene'] = $("input[name='shop_hygiene']").val();
            data['shop_bank'] = $("input[name='shop_bank']").val();
            data['shop_just'] = $("input[name='shop_just']").val();
            data['shop_back'] = $("input[name='shop_back']").val();
            data['qq_email'] = $("input[name='qq_email']").val();
            data['shop_doorway'] = $("input[name='shop_doorway']").val();
            data['shop_images'] = $("input[name='shop_images']").val();
            data['shop_bank_add'] = $("input[name='shop_bank_add']").val();
            data['id'] = "<?php echo $member_info[0]['id']; ?>";
            data['is_vip'] = "<?php echo $member_info[0]['is_vip']; ?>";
            data['invite_code'] = $("input[name='invite_code']").val();
            if(data['avatar'] == ''){layer.open({content: '商户头像为必选项',skin: 'msg',time: 2});return;}
            if(data['username'] == ''){layer.open({content: '商户名称为必填项',skin: 'msg',time: 2});return;}
            <?php if($member_info[0]['is_vip'] == 3 || !empty($invite_code)){ ?>
            if(data['shop_yyzz'] == ''){layer.open({content: '营业执照为必选项',skin: 'msg',time: 2});return;}
            if(data['shop_bank'] == ''){layer.open({content: '结算银行卡为必填项',skin: 'msg',time: 2});return;}
            if(data['shop_just'] == ''){layer.open({content: '身份证正面为必选项',skin: 'msg',time: 2});return;}
            if(data['shop_back'] == ''){layer.open({content: '身份证反面为必选项',skin: 'msg',time: 2});return;}
            // if(data['qq_email'] == ''){layer.open({content: 'qq邮箱为必填项',skin: 'msg',time: 2});return;}
            if(data['shop_doorway'] == ''){layer.open({content: '店铺门头为必填项',skin: 'msg',time: 2});return;}
            if(data['shop_images'] == ''){layer.open({content: '店内照片为必填项',skin: 'msg',time: 2});return;}
            if(data['shop_bank_add'] == ''){layer.open({content: '开户行地址为必填项',skin: 'msg',time: 2});return;}
            if(data['shop_add'] == ''){layer.open({content: '商户地址为必填项',skin: 'msg',time: 2});return;}
            if(data['shop_lat'] == ''){layer.open({content: '未查询到此地址信息',skin: 'msg',time: 2});return;}
            if(data['sort'] == ''){layer.open({content: '商户分类为必选项',skin: 'msg',time: 2});return;}
            <?php } ?>
            if(data['mobile'] == ''){
                layer.open({content: '手机号码为必填项，请重新输入',skin: 'msg',time: 2});
                return;
            }
            if(!isPhoneNo(data['mobile'])){
                layer.open({content: '手机号格式不正确，请重新输入',skin: 'msg',time: 2});
                return;
            }
            if(data['shop_spot'] == 1){
                if(data['shop_spot_ratio'] == ''){
                    layer.open({content: '拍客返点有时，必须输入返点比例',skin: 'msg',time: 2});
                    return;
                }
            }
            console.log(data['sort']);
            $.ajax({
                url: 'shop_ajax.php',
                type: "post",
                data: data,
                dataType: 'json',
                success:function(res){
                    // console.log(res);
                    if(res.status == 'y'){
                        layer.open({content: res.info,skin: 'msg',time: 2 });
                        location.href="member.php";
                    }else{
                        layer.open({content: res.info,skin: 'msg',time: 2 });
                    }
                }
            })


        })
        $(".zanNumDialog").find('input').change(function(){
            $(".zanBox").find('em').html($(this).val());
        })
        $("textarea[name='praise_award']").change(function(){
            $(".praise_award").html($(this).val());
        })
        // ---------------------美丽的破折号⬇公共部分---------
        //确认按钮点击事件
        var confirmFnc = null
        var selector = "" //显示的dialogContent内的选择器

        var mask = mui.createMask(function () {
            $(".dialog").hide()
            $(".titleName").text("")
            $(selector).hide()
            confirmFnc = null
            selector = ''
        }); //callback为用户点击蒙版时自动执行的回调；

        function closeMask() {
            $(".dialog").hide()
            $(".titleName").text("")
            $(selector).hide()
            mask.close()
            confirmFnc = null
            selector = ''
        }

        //点击关闭按钮关闭遮罩
        $('.mui-icon-closeempty').click(function () {
            closeMask()
        })


        var map = new AMap.Map("wrapper", {
            resizeEnable: true
        });
        var geocoder = new AMap.Geocoder();
        var marker = new AMap.Marker();
        function geoCode() {
            var address  = document.getElementById('shop_add').value;
                $("input[name='shop_lng']").attr('value','');
                $("input[name='shop_lat']").attr('value','');
            geocoder.getLocation(address, function(status, result) {
                if (status === 'complete'&&result.geocodes.length) {
                    var lnglat = result.geocodes[0].location
                    $("input[name='shop_lng']").attr('value', lnglat.lng);
                    $("input[name='shop_lat']").attr('value', lnglat.lat);
                    console.log(lnglat);
                    // document.getElementById('lnglat').value = lnglat;
                    // marker.setPosition(lnglat);
                    // map.add(marker);
                    // map.setFitView(marker);
                }else{
                    layer.open({content: '未查询到该地址信息',skin: 'msg',time: 2});
                }
            });
        }
        $("#shop_add").change(function(){
            geoCode();
        })





        //上传压缩图片
        $(".file_up").click(function(){
            var shop_type = $(this).attr('shop_type');
            // console.log(shop_type);
            // return;
            $("#file").attr('shop_type',shop_type);
            $('#file').click();
        })

        function changepic(obj) {
            if (!obj.files || !obj.files[0]) {
                return;
            }
            var form = new FormData();
            var fileObj = obj.files[0];
            if(fileObj.size/1024 > 1025) {
                photoCompress(fileObj, {quality: 0.2}, function(base64Codes){
                    var bl = new window.File([convertBase64UrlToBlob(base64Codes)], 'test.jpeg', {
                                type: 'image/jpg,image/jpeg,image/png,image/PNG'
                            });
                    form.append("file", bl);
                    sendToSever(form);
                })
            } else {
                form.append("file", fileObj)
                sendToSever(form);
            }
        }

            // var aaa;
            // function changepic(obj) {
            //     // $('#fileImg').removeClass('fileIcon').addClass('newImg');
            //     if (!obj.files || !obj.files[0]) {
            //         return;
            //     }

            //     // 找到canvas,准备画图
            //     var canvas = document.getElementById('canvas');
            //     var context = canvas.getContext('2d');


            //     file = obj.files[0];
            //     // console.log(file)
            //     // console.log('file', file)



            //     var reader = new FileReader();
            //     reader.readAsDataURL(file);
            //     reader.onload = function (evt) {
            //         // console.log(reader.result);
            //         // if (reader.result.size > 2048) {
            //         //     layer.open({
            //         //         content: '文件大小需在2M以内！',
            //         //         skin: 'msg',
            //         //         time: 2 //2秒后自动关闭
            //         //     });
            //         // }

            //         //获取的是图片的base64代码
            //         var replaceSrc = evt.target.result;
            //         //定义一个Image对象
            //         var image = new Image();
            //         image.src = replaceSrc;
            //         image.onload = function () {
            //             //获取的是图片的base64代码
            //             var replaceSrc = evt.target.result;

            //             //定义一个Image对象
            //             var image = new Image();
            //             image.src = replaceSrc;
            //             image.onload = function () {

            //                 // 加载完毕后获取图片的原始尺寸
            //                 var origin_width = this.width;
            //                 var origin_height = this.height;
            //                 console.log("原始图片宽度：" + origin_width + " px");
            //                 console.log("原始图片高度：" + origin_height + " px");
            //                 // 设置最大允许宽高,根据需求自己设置,值越大,图片大小越大
            //                 var max_width = 500;
            //                 var max_height = 500;

            //                 // 最终宽高
            //                 target_width = origin_width;
            //                 target_height = origin_height;
            //                 if (origin_width > max_width || origin_height > max_height) {
            //                     if (origin_width / origin_height > max_width / max_height) {
            //                         // 更宽，按照宽度限定尺寸
            //                         target_width = max_width;
            //                         target_height = Math.round(max_width * (origin_height / origin_width));
            //                     } else {
            //                         target_height = max_height;
            //                         target_width = Math.round(max_height * (origin_width / origin_height));
            //                     }
            //                 }

            //                 console.log("格式化图片宽度：" + target_width + " px");
            //                 console.log("格式化图片高度：" + target_height + " px");

            //                 canvas.width = target_width;
            //                 canvas.height = target_height;
            //                 // 绘画到画布上
            //                 context.drawImage(image, 0, 0, target_width, target_height);

            //                 //此处得到的是blob对象,blob对象是在ie10及以上才兼容,在ios8_1_1上和iphoneSE上有兼容问题
            //                 // canvas.toBlob(function (res) {
            //                 //     console.log(res);
            //                 //     formData.append("file", res);
            //                 //     // formData.append("openid", openid);
            //                 // });

            //                 // 读取canvas的数据
            //                 var result = canvas.toDataURL();


            //                 var arr = result.split(','),
            //                     mime = arr[0].match(/:(.*?);/)[1], // 转成blob
            //                     bstr = atob(arr[1]),
            //                     n = bstr.length,
            //                     u8arr = new Uint8Array(n);
            //                 while (n--) {
            //                     u8arr[n] = bstr.charCodeAt(n);
            //                 }
            //                 aaa = new window.File([new Blob([u8arr], {
            //                     type: mime
            //                 })], 'test.jpeg', {
            //                     type: 'image/jpg,image/jpeg,image/png,image/PNG'
            //                 }) // 转成file
            //                 // console.log('00', aaa)
            //                 // console.log('000formData:', formData)
            //                 // 得到的结果是base64位的字符串,拿到压缩后的值通过网络请求交给后台处理...
            //                 // 如果是blob对象,需要通过FormData对象发送
            //                 // console.log('最终图片链接',result); //最终图片链接

            //                 //最终图片宽高
            //                 // console.log("压缩后图片宽度：" + target_width + " px");
            //                 // console.log("压缩后图片高度：" + target_height + " px");
            //                 // 再将获取值赋给img标签
            //                 $('#fileImg').attr("src", result);

            //                 var formData = new FormData();
            //                 formData.append("file", aaa);
            //                 sendToSever(formData);
            //             }
            //         }
            //     }
            // }
        function getFileName(o) {
            var pos = o.lastIndexOf("\\");
            return o.substring(pos + 1);
        }

        function sendToSever(formData) {
            // alert('3333333');
            $.ajax({
                url: 'fileup_img.php',
                type: "post",
                data: formData,
                dataType: 'json',
                processData: false, // 使数据不做处理
                contentType: false, // 不要设置Content-Type请求头
                timeout: 10000,
                beforeSend: function () {
                    lid = layer.open({
                        type: 2,
                        content: '提交中...',
                        shadeClose: false
                    });
                },
                success: function (res) {
                    if (res.status == 'y') {
                        layer.open({
                            content: res.info,
                            skin: 'msg',
                            time: 2 //2秒后自动关闭
                        });
                    } else {
                        layer.open({
                            content: res.info,
                            skin: 'msg',
                            time: 2 //2秒后自动关闭
                        });
                    }
                    var shop_type = $("#file").attr('shop_type');
                    $("."+shop_type).find("img").attr('src',res.src);
                    $("."+shop_type).find("img").show();
                    $("input[name='"+shop_type+"']").attr('value', res.src);
                    $("."+shop_type).find("div").hide();
                    console.log(shop_type);
                    return;
                    // _img = "https://5p8.fyh5p8.com/xiaochengxu/"+res.src;
                    // _img = res.src;
                    // var img_type = $("#file").attr('data-type');
                    // if(img_type == 'goods_img'){
                    //     $(".goods_img").attr('src', _img);
                    //     $("input[name='goods_img']").val(_img);
                    //     $(".goods_img").parent().find('div').hide();
                    // }else{
                    //     html = '<li style="list-style: none;position:relative;""><img class="del_info" style="width:100%;" src="'+_img+'" alt=""><img style="position: absolute;top: 10px;width: 30px;right: 10px;" src="images/delite.png" alt=""><input type="hidden" class="goods_img" name="goods_img" value="'+_img+'"></li>';
                    //     // html = '<li style="list-style: none;position:relative;""><img class="del_info" style="width:100%;" src="'+_img+'" alt=""><img style="position: absolute;top: 10px;width: 30px;right: 10px;" src="images/delite.png" alt=""><input type="hidden" class="goods_img" name="goods_img" value="'+_img+'"></li>';
                    //     $(".goods_ils").append(html);
                    // }
                    // console.log(_img);
                },
                complete: function () {
                    layer.close(lid);
                },
                error: function (XMLHttpRequest, textStatus) {
                    layer.close(lid);
                    if ('timeout' == textStatus) {
                        alert('请求接口超时！');
                    } else {
                        alert(JSON.stringify(XMLHttpRequest))
                    }
                }
            });
        }

        //dialog显示
        function showDialog(dom, title) {
            mask.show(); //显示遮罩
            $(".dialog").show()
            $(".titleName").text(title)
            $(dom).show()
            selector = dom
        }

        //确认点击
        $(".confirmBtn").click(function () {
            confirmFnc()
            closeMask()
        })
        // -------------------------美丽的破折号---------------------

        //名称修改
        // $(".name").click(function () {
        //     showDialog(".nameDialog", "用户名")
        //     confirmFnc = function () {
        //         console.log($('.nameInput').val())
        //         // $('.nameInput').value
        //     }
        // })

        // 拍客视频获赞奖励
        $(".zanBox .info").click(function () {
            showDialog(".zanRewardDiaLog", "拍客视频获赞奖励")
            confirmFnc = function () {
                // console.log($('.nameInput').val())
                // $('.nameInput').value
            }
        })

        // 拍客视频获赞数量
        $(".zanBox .lab").click(function () {
            showDialog(".zanNumDialog", "拍客视频获赞数量")
            confirmFnc = function () {
                // console.log($('.nameInput').val())
                // $('.nameInput').value
            }
        })

        // 获赞成功返点
        // $(".percentage").click(function () {
        //     showDialog(".rewardPercentageDialog", "拍客推荐顾客购买成功返点")
        //     confirmFnc = function () {
        //         // console.log($('.nameInput').val())
        //         // $('.nameInput').value
        //     }
        // })

        // $(".license").click(function () {
        //     mui('#sheet2').popover('toggle');
        // })

        // $(".headImg").click(function () {
        //     mui('#sheet2').popover('toggle');
        // })

        // $(".qrCode").click(function () {
        //     mui('#sheet1').popover('toggle');
        // })
    </script>
</body>

</html>
